package es.ats.codington.festival.services;

import es.ats.codington.festival.daos.ImageDAOImp;
import es.ats.codington.festival.domain.Image;
import es.ats.codington.festival.exceptions.ServiceException;
import es.ats.codington.festival.interfaces.services.IImageService;
import es.ats.codington.festival.utils.FERSDataConnection;

public class ImageService implements IImageService {
	private ImageDAOImp idi;
	private Image im;
	

	public ImageService() {
		super();
		idi=new ImageDAOImp();
		im=new Image();
	}

	public ImageService(ImageDAOImp idi, Image im) {
		super();
		this.idi = idi;
		this.im = im;
	}	
	
	public ImageDAOImp getIdi() {
		return idi;
	}

	public void setIdi(ImageDAOImp idi) {
		this.idi = idi;
	}

	public Image getIm() {
		return im;
	}

	public void setIm(Image im) {
		this.im = im;
	}

	@Override
	public Image checkPhotoById(int photoId) throws ServiceException {
		FERSDataConnection fdc=idi.getCon();
        try{
                fdc.connect();
                Image img=idi.getPhotoById(photoId);
                fdc.disconnect();
                return img;
        }
        catch (Exception ex) {
                throw new ServiceException("Service checkEventPlaceById failure:"+ex.getMessage(), ex);
        }
	}
	
	@Override
	public int insertImage(Image img) throws ServiceException {
		FERSDataConnection fdc=idi.getCon();
        try{
                fdc.connect();
                int id=idi.insertImage(img);
                fdc.disconnect();
                return id;
        }
        catch (Exception ex) {
                throw new ServiceException("Service insertImage failure:"+ex.getMessage(), ex);
        }
	}

}
